package com.javaEE.gamepigeon.controller;


import com.javaEE.gamepigeon.entity.Department;
import com.javaEE.gamepigeon.service.DepartmentService;
import com.javaEE.gamepigeon.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "专业相关接口")
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    @GetMapping("/query")
    @ApiOperation("获取所有专业")
    public List<Department> queryDepartment(){
        return departmentService.list();
    }


    @PostMapping("/add")
    @ApiOperation("添加专业")
    public Result addDepartment(@RequestBody Department department){
        if(departmentService.saveOrUpdate(department)){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除专业")
    public Result deleteDepartment(@PathVariable Integer id){
        if(departmentService.removeById(id)){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }

//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "departmentId",value = "专业对应的ID",paramType = "query"),
//            @ApiImplicitParam(name = "newDepartmentName",value = "专业名称",paramType = "query")
//    })
//    @GetMapping("/update")
//    @ApiOperation("更新专业")
//    public Result updateDepartment(Integer departmentId, String newDepartmentName){
//        if(departmentService.updateDepartment(departmentId,newDepartmentName)){
//            return Result.success("更新成功");
//        }else{
//            return Result.error("更新失败");
//        }
//    }

}
